package com.fr.chart.plot;

import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.BaseXMLUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.axis.SeriesAttrAlpha;
import com.fr.chart.axis.SeriesAttrColor;
import com.fr.chart.axis.SeriesAttrLine;
import com.fr.chart.axis.SeriesAttrMarkerType;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.glyph.SoloGlyph;
import com.fr.chart.marker.Marker;
import com.fr.chart.marker.MarkerFactory;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;

public class MarkerGlyph extends SoloGlyph
{
  private static final long serialVersionUID = 7868484475190979219L;
  public static final String XML_TAG = "MarkerGlyph";
  private Marker marker;
  private Color color;
  private double x;
  private double y;
  private double width;
  private double height;
  private float alpha = 1.0F;

  public MarkerGlyph()
  {
  }

  public MarkerGlyph(Marker paramMarker, Color paramColor)
  {
    setMarker(paramMarker);
    setColor(paramColor);
  }

  public MarkerGlyph(Marker paramMarker, Color paramColor, double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4)
  {
    setMarker(paramMarker);
    setColor(paramColor);
    this.x = paramDouble1;
    this.y = paramDouble2;
    this.width = paramDouble3;
    this.height = paramDouble4;
  }

  public void draw(Graphics paramGraphics)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    if (getMarker() == null)
      return;
    Paint localPaint = localGraphics2D.getPaint();
    Composite localComposite = localGraphics2D.getComposite();
    localGraphics2D.setComposite(AlphaComposite.getInstance(3, getAlpha()));
    if (getColor() != null)
      localGraphics2D.setPaint(getColor());
    getMarker().paint(localGraphics2D, this.x + this.width / 2.0D, this.y + this.height / 2.0D);
    localGraphics2D.setPaint(localPaint);
    localGraphics2D.setComposite(localComposite);
  }

  public Shape getShape()
  {
    return new Rectangle2D.Double(this.x, this.y, this.width, this.height);
  }

  public void setShape(Rectangle2D paramRectangle2D)
  {
    this.x = paramRectangle2D.getX();
    this.y = paramRectangle2D.getY();
    this.width = paramRectangle2D.getWidth();
    this.height = paramRectangle2D.getHeight();
  }

  public void setMarker(Marker paramMarker)
  {
    this.marker = paramMarker;
  }

  public Marker getMarker()
  {
    return this.marker;
  }

  public void setColor(Color paramColor)
  {
    this.color = paramColor;
  }

  public Color getColor()
  {
    return this.color;
  }

  public void setAlpha(float paramFloat)
  {
    this.alpha = paramFloat;
  }

  public float getAlpha()
  {
    return this.alpha;
  }

  public void dealCondition(SeriesCollection paramSeriesCollection, int paramInt)
  {
    SeriesAttrMarkerType localSeriesAttrMarkerType = (SeriesAttrMarkerType)paramSeriesCollection.getSeriesCondition(new SeriesAttrMarkerType(), paramInt);
    setMarker(MarkerFactory.createIndexMarker(localSeriesAttrMarkerType.getMarkerTypeIndex()));
    SeriesAttrColor localSeriesAttrColor = (SeriesAttrColor)paramSeriesCollection.getSeriesCondition(new SeriesAttrColor(), paramInt);
    setColor(localSeriesAttrColor.getSeriesColor());
    SeriesAttrAlpha localSeriesAttrAlpha = (SeriesAttrAlpha)paramSeriesCollection.getSeriesCondition(new SeriesAttrAlpha(), paramInt);
    setAlpha(localSeriesAttrAlpha.getAlpha());
  }

  public void dealCondition4Line(SeriesCollection paramSeriesCollection, int paramInt)
  {
    SeriesAttrMarkerType localSeriesAttrMarkerType = (SeriesAttrMarkerType)paramSeriesCollection.getSeriesCondition(new SeriesAttrMarkerType(), paramInt);
    Marker localMarker = MarkerFactory.createIndexMarker(localSeriesAttrMarkerType.getMarkerTypeIndex());
    setMarker(localMarker);
    SeriesAttrLine localSeriesAttrLine = (SeriesAttrLine)paramSeriesCollection.getSeriesCondition(new SeriesAttrLine(), paramInt);
    localMarker.setColor(localSeriesAttrLine.getSeriesLineColor());
    setColor(localSeriesAttrLine.getSeriesLineColor());
    SeriesAttrAlpha localSeriesAttrAlpha = (SeriesAttrAlpha)paramSeriesCollection.getSeriesCondition(new SeriesAttrAlpha(), paramInt);
    setAlpha(localSeriesAttrAlpha.getAlpha());
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("x")) != null)
          this.x = Double.valueOf(str2).doubleValue();
        if ((str2 = paramXMLableReader.getAttr("y")) != null)
          this.y = Double.valueOf(str2).doubleValue();
        if ((str2 = paramXMLableReader.getAttr("width")) != null)
          this.width = Double.valueOf(str2).doubleValue();
        if ((str2 = paramXMLableReader.getAttr("height")) != null)
          this.height = Double.valueOf(str2).doubleValue();
        if ((str2 = paramXMLableReader.getAttr("alpha")) != null)
          setAlpha(Float.valueOf(str2).floatValue());
        if ((str2 = paramXMLableReader.getAttr("color")) != null)
          setColor(new Color(Integer.parseInt(str2), true));
      }
      else if (str1.equals("Marker"))
      {
        setMarker(BaseXMLUtils.readMarker(paramXMLableReader));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("MarkerGlyph");
    paramXMLPrintWriter.startTAG("Attr").attr("x", this.x).attr("y", this.y).attr("width", this.width).attr("height", this.height).attr("alpha", this.alpha);
    if (getColor() != null)
      paramXMLPrintWriter.attr("color", getColor().getRGB());
    paramXMLPrintWriter.end();
    if (getMarker() != null)
      BaseXMLUtils.writeMarker(paramXMLPrintWriter, getMarker());
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof MarkerGlyph))
      return false;
    MarkerGlyph localMarkerGlyph = (MarkerGlyph)paramObject;
    if (localMarkerGlyph.getAlpha() != getAlpha())
      return false;
    if ((localMarkerGlyph.x != this.x) || (localMarkerGlyph.y != this.y) || (localMarkerGlyph.width != this.width) || (localMarkerGlyph.height != this.height))
      return false;
    if (!(Equals.equals(localMarkerGlyph.getColor(), getColor())))
      return false;
    return (Equals.equals(localMarkerGlyph.getMarker(), getMarker()));
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    localJSONObject.put("alpha", this.alpha);
    localJSONObject.put("color", this.color);
    return localJSONObject;
  }
}